package com.iknow.ui.model;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Build.VERSION;
import android.text.Spannable;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.iknow.IKnow;
import com.iknow.IKnowApiV4;
import com.iknow.activity.ImageZoomActivity;
import com.iknow.activity.WebViewActivity;
import com.iknow.app.IKnowSystemConfig;
import com.iknow.image.ImageCache;
import com.iknow.image.ImageManager;
import com.iknow.image.ProfileImageCacheManager;
import com.iknow.util.Loger;
import com.iknow.util.SpannableUtil;
import com.iknow.util.StringUtil;
import com.iknow.util.enums.IKTagEnum;
import com.iknow.view.widget.SelectScreenManager;
import com.iknow.xml.IKValuePageData.IKValuePageData_Item;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class IKPageAdapter extends BaseAdapter
{
  private final String TAG = "IKPageAdapter";
  private final int VIEW_A;
  private final int VIEW_AUDIO;
  private final int VIEW_BR;
  private final int VIEW_HEADER;
  private final int VIEW_HR;
  private final int VIEW_IMAGE;
  private final int VIEW_TEXT;
  private final int VIEW_UNKNOW = 0;
  private final int VIEW_VIDEO;
  protected String formatFileUrl;
  private IKValuePageData.IKValuePageData_Item mAudioDataItem;
  private OnFireOnAudioEvent mAudioEventListener;
  protected Context mContext;
  private List<IKValuePageData.IKValuePageData_Item> mHtmlNodeList;
  private View.OnClickListener mImageClickListener;
  private LayoutInflater mInflater;
  private ProfileImageCacheManager mProfileImageCacheManager;
  protected SelectScreenManager mSelectScreenManager;
  private String title;
  private Map<String, View> viewCache;

  public IKPageAdapter(Context paramContext, LayoutInflater paramLayoutInflater)
  {
    this.VIEW_TEXT = 1;
    this.VIEW_IMAGE = 2;
    this.VIEW_AUDIO = 3;
    this.VIEW_VIDEO = 4;
    this.VIEW_HR = 5;
    this.VIEW_BR = 6;
    this.VIEW_HEADER = 7;
    this.VIEW_A = 8;
    this.mContext = null;
    this.formatFileUrl = null;
    this.mHtmlNodeList = new ArrayList();
    this.viewCache = new HashMap();
    this.mSelectScreenManager = null;
    this.title = null;
    this.mImageClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        Intent localIntent = new Intent();
        localIntent.setClass(this.this$0.mContext, ImageZoomActivity.class);
        localIntent.putExtra("imageUrl", IKPageAdapter.access$1(this.this$0, this.this$0.formatFileUrl));
        this.this$0.mContext.startActivity(localIntent);
      }
    };
    this.mContext = paramContext;
    this.mProfileImageCacheManager = new ProfileImageCacheManager();
    this.mInflater = paramLayoutInflater;
  }

  private String getImageUrl(String paramString)
  {
    String str;
    int i = paramString.indexOf("path=");
    if (-1 == i)
      str = paramString;
    while (true)
    {
      return str;
      int j = paramString.lastIndexOf("&width");
      str = IKnowApiV4.formatFileUrl(paramString.substring(i + 5, j));
    }
  }

  public void addHtmlNode(IKValuePageData.IKValuePageData_Item paramIKValuePageData_Item)
  {
    this.mHtmlNodeList.add(paramIKValuePageData_Item);
  }

  public View audioView(Map<String, Object> paramMap)
  {
    return null;
  }

  public void clearAllImage()
  {
    this.mProfileImageCacheManager.getImageManager().clear();
    this.mProfileImageCacheManager.cancelImageTask();
    this.mProfileImageCacheManager = null;
  }

  public View createView(IKValuePageData.IKValuePageData_Item paramIKValuePageData_Item, int paramInt)
  {
    Object localObject;
    if (paramIKValuePageData_Item == null)
    {
      View localView1 = new View(this.mContext);
      localView1.setVisibility(8);
      localObject = localView1;
    }
    while (true)
    {
      while (true)
      {
        while (true)
        {
          while (true)
          {
            while (true)
            {
              return localObject;
              if (1 != paramInt)
                break;
              localObject = textView(paramIKValuePageData_Item.data);
            }
            if (3 != paramInt)
              break;
            localObject = audioView(paramIKValuePageData_Item.data);
          }
          if (4 != paramInt)
            break;
          localObject = videoView(paramIKValuePageData_Item.data);
        }
        if (2 != paramInt)
          break;
        localObject = imageView(paramIKValuePageData_Item.data);
      }
      View localView2 = new View(this.mContext);
      localView2.setVisibility(8);
      localObject = localView2;
    }
  }

  public int getCount()
  {
    int i;
    if (this.mHtmlNodeList == null)
      i = 0;
    while (true)
    {
      return i;
      i = this.mHtmlNodeList.size();
    }
  }

  public IKValuePageData.IKValuePageData_Item getItem(int paramInt)
  {
    IKValuePageData.IKValuePageData_Item localIKValuePageData_Item;
    if (this.mHtmlNodeList == null)
      localIKValuePageData_Item = null;
    while (true)
    {
      return localIKValuePageData_Item;
      localIKValuePageData_Item = (IKValuePageData.IKValuePageData_Item)this.mHtmlNodeList.get(paramInt);
    }
  }

  public long getItemId(int paramInt)
  {
    return paramInt;
  }

  public int getItemViewType(int paramInt)
  {
    int i;
    IKValuePageData.IKValuePageData_Item localIKValuePageData_Item = getItem(paramInt);
    if (localIKValuePageData_Item == null)
      i = 0;
    while (true)
    {
      while (true)
      {
        while (true)
        {
          while (true)
          {
            while (true)
            {
              return i;
              if (localIKValuePageData_Item.type != IKTagEnum.TEXT)
                break;
              i = 1;
            }
            if (localIKValuePageData_Item.type != IKTagEnum.IMAGE)
              break;
            i = 2;
          }
          if (localIKValuePageData_Item.type != IKTagEnum.AUDIO)
            break;
          i = 0;
        }
        if (localIKValuePageData_Item.type != IKTagEnum.VIDEO)
          break;
        i = 4;
      }
      i = 0;
    }
  }

  public String getTitle()
  {
    return this.title;
  }

  public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
  {
    View localView = createView(getItem(paramInt), getItemViewType(paramInt));
    this.mSelectScreenManager.registerOnTouchListener(localView);
    localView.setBackgroundResource(0);
    return localView;
  }

  public int getViewTypeCount()
  {
    return 9;
  }

  public View imageView(Map<String, Object> paramMap)
  {
    ImageView localImageView;
    String str = (String)paramMap.get("src");
    if (this.viewCache.containsKey(str))
    {
      localImageView = (ImageView)this.viewCache.get(str);
      localImageView.setAdjustViewBounds(true);
      if (StringUtil.isEmpty(str))
        break label194;
      Bitmap localBitmap = localImageView.getDrawingCache();
      if ((localBitmap != null) && (localBitmap != ImageCache.mDefaultBitmap))
      {
        if (!(localBitmap.isRecycled()))
        {
          Loger.i("IKPageAdapter", "recycle--" + localBitmap.toString());
          localBitmap.recycle();
        }
        localImageView.setDrawingCacheEnabled(false);
      }
    }
    try
    {
      localImageView.setDrawingCacheEnabled(true);
      this.formatFileUrl = IKnowApiV4.formatFileUrl(str);
      this.mProfileImageCacheManager.displayContentBimap(localImageView, this.formatFileUrl);
      localImageView.setOnClickListener(this.mImageClickListener);
      return localImageView;
      localImageView = (ImageView)this.mInflater.inflate(2130903049, null);
      label194: this.viewCache.put(str, localImageView);
    }
    catch (RuntimeException localRuntimeException)
    {
      while (true)
      {
        while (true)
          Loger.e("IKPageAdapter", localRuntimeException.getMessage());
        localImageView.setImageResource(2130837552);
      }
    }
  }

  public void onDestroy()
  {
    if (this.mHtmlNodeList != null)
      this.mHtmlNodeList.clear();
    this.viewCache.clear();
    this.viewCache = null;
    this.mContext = null;
    this.mSelectScreenManager = null;
    this.mHtmlNodeList = null;
  }

  public void onStop()
  {
  }

  public void setAudioDataItem(IKValuePageData.IKValuePageData_Item paramIKValuePageData_Item)
  {
    this.mAudioDataItem = paramIKValuePageData_Item;
    if (this.mAudioEventListener != null)
      this.mAudioEventListener.onAudioEvent(paramIKValuePageData_Item);
  }

  public void setAudioEventListener(OnFireOnAudioEvent paramOnFireOnAudioEvent)
  {
    this.mAudioEventListener = paramOnFireOnAudioEvent;
  }

  public void setHtmlNodeList(List<IKValuePageData.IKValuePageData_Item> paramList)
  {
    this.mHtmlNodeList = paramList;
  }

  public void setSelectScreenManager(SelectScreenManager paramSelectScreenManager)
  {
    this.mSelectScreenManager = paramSelectScreenManager;
  }

  public void setTitle(String paramString)
  {
    this.title = paramString;
  }

  public View textView(Map<String, Object> paramMap)
  {
    Spannable localSpannable = (Spannable)paramMap.get("text");
    TextView localTextView = (TextView)this.mInflater.inflate(2130903050, null);
    localTextView.setText(SpannableUtil.reflesh(localSpannable));
    localTextView.setTextColor(IKnow.mSystemConfig.getBook_TextColor());
    localTextView.setLineSpacing(0F, 1.2000000476837158F);
    localTextView.setMovementMethod(LinkMovementMethod.getInstance());
    return localTextView;
  }

  public View videoView(Map<String, Object> paramMap)
  {
    String str1 = (String)paramMap.get("flash");
    float f = Float.parseFloat(Build.VERSION.RELEASE.substring(0, 3));
    int i = str1.indexOf("src");
    int j = str1.indexOf("swf");
    String str2 = str1.substring(i + 5, j + 3);
    View localView = this.mInflater.inflate(2130903051, null);
    ImageView localImageView = (ImageView)localView.findViewById(2131296301);
    TextView localTextView = (TextView)localView.findViewById(2131296302);
    if (f < 2.2000000000000002D)
      localTextView.setText("您的手机系统版本过低，不支持flash视频播放");
    while (true)
    {
      localImageView.setAdjustViewBounds(true);
      localImageView.setImageResource(2130837720);
      return localView;
      localImageView.setOnClickListener(new View.OnClickListener(this, str2)
      {
        public void onClick()
        {
          Intent localIntent = new Intent(this.this$0.mContext, WebViewActivity.class);
          localIntent.putExtra("flash", this.val$url);
          this.this$0.mContext.startActivity(localIntent);
        }
      });
    }
  }

  public static abstract interface OnFireOnAudioEvent
  {
    public abstract void onAudioEvent(IKValuePageData.IKValuePageData_Item paramIKValuePageData_Item);
  }
}